<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>回文对</title>
</head>
<body>
  <script>
    // 暴力回调方法
    function fn(words) {
      const res = []
      for (let i = 0; i < words.length - 1; i++) {
        for (let j = i + 1; j < words.length; j++) {
          let temp1 = words[i] + words[j], temp2 = words[j] + words[i]
          if (fm(temp1)) res.push([i, j])
          if (fm(temp2)) res.push([j, i])
        }
      }
      return res
    }
    function fm(s) {
      let l = 0;
      let r = s.length - 1;
      while (l < r) {
        if (s[l] != s[r]) return false
        l++
        r--
      }
      return true
    }
    console.log(fn(['bat', 'tab', 'cat']))
  </script>
</body>
</html>